﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DTN.Core;
using Hanel.DTN.News;

public partial class Control_Home_Vote : System.Web.UI.UserControl
{
    ItblVoteCriteriaManager objVoteCri = tblVoteCriteriaManager.CreateInstance();
    ItblVotesManager objvotes = tblVotesManager.CreateInstance();
    int IDVote = 0;

    string time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.000");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;
        bindRadioList();
        //sendVote();
       
    }
    private void bindRadioList()
    {
         
        DataTable dt = objvotes.SelecttblVotesDynamic_top("Top 1", "[status]=1 and StartDate<='" + time + "' and EndDate>='" + time + "'", "VoteId");
        DataTable dt2 = objVoteCri.SelecttblVoteCriteriaDynamic("[status]=1 and Voteid=" + dt.Rows[0]["Voteid"].ToString(), "VCID");
        IDVote = int.Parse(dt.Rows[0]["Voteid"].ToString());

        for (int i = 0; i < dt2.Rows.Count; i++)
        {
            DataRow dr = dt2.Rows[i];
            RadioButtonList1.Items.Add(new ListItem("" + dr["VCName"] + "", "" + dr["VCID"] + ""));
        }
    }
    //protected void sendVote()
    //{
    //    string VCID = RadioButtonList1.SelectedValue;
    //    //int VCID = int.Parse(RadioButtonList1.SelectedValue.ToString());
    //    ImageButton1.Attributes.Add("onclick", "javascript:window.open('Vote/Vote.aspx?id=" + VCID + "', 'window','HEIGHT=500,WIDTH=420,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes')");
    //}
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        int VCID = int.Parse(RadioButtonList1.SelectedValue);


        Response.Write("<script language='javascript'>");
        Response.Write("window.open('Vote/Vote.aspx?ID=" + VCID + "', 'window','HEIGHT=500,WIDTH=420,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes');");
        Response.Write(" </script>");

        //Response.Redirect("Vote/Vote.aspx?id=" + VCID);

      
    }
}